package com.dc.service.impl;

import com.dc.entity.Shop;
import com.dc.service.ShopService;
import com.dc.tools.DBTools;
import com.dc.tools.PageData;

public class ShopServiceImpl implements ShopService {

	@Override
	public boolean addShop(Shop shop) {
		if (shop != null) {
			String sql = "insert into shop values(null,?,?,?,?,?,?,?,?,?,?)";
			int n = DBTools.exUpdate(sql, shop.getShopname(), shop.getShoppsw(), shop.getShopphone(),
					shop.getShopemail(), true, shop.getShopaddress(), shop.getShopdianming(), shop.getShopdate(),
					shop.getShopimage(), shop.getShoptime());
			return n > 0;
		}
		return false;
	}

	@Override
	public boolean deleteShop(int shopid) {
		// TODO Auto-generated method stub
		String sql = "delete from shop where shopid=?";
		int n = DBTools.exUpdate(sql, shopid);
		return n > 0;
	}

	@Override
	public boolean updateShop(Shop shop) {
		// TODO Auto-generated method stub
		if (shop != null) {
			String sql = "update shop set shopname=?,shoppsw=?,shopphone=?,shopemail=?,shopstate=?,shopaddress=?,shopdianming=?,shopdate=?,shopimage=?,shoptime=? where shopid=?";
			int n = DBTools.exUpdate(sql, shop.getShopname(), shop.getShoppsw(), shop.getShopphone(),
					shop.getShopemail(), shop.isShopstate(), shop.getShopaddress(), shop.getShopdianming(),
					shop.getShopdate(), shop.getShopimage(), shop.getShoptime(), shop.getShopid());
			return n > 0;
		}
		return false;

	}

	@Override
	public Object selectShop(String keywords) {
		// TODO Auto-generated method stub
		String sql = "select * from shop where shopdianming like ?";
		Object list = DBTools.exQuery(sql, Shop.class, "%" + keywords + "%");
		return list;
	}

	@Override
	public PageData<Shop> selectShopByPage(int page, int pageSize, String keywords) {
		// TODO Auto-generated method stub
		String sql = "select * from shop where shopdianming like ?";
		PageData<Shop> pd = DBTools.exQueryByPage(sql, Shop.class, page, pageSize, "%" + keywords + "%");
		return pd;
	}

	@Override
	public Object selectShopByShopName(String shopname) {
		// TODO Auto-generated method stub
		String sql = "select * from shop where shopname=?";
		Object list = DBTools.exQuery(sql, Shop.class, shopname);
		return list;
	}

	@Override
	public Object selectShopByShopPhone(String shopphone) {
		// TODO Auto-generated method stub
		String sql = "select * from shop where shopphone=?";
		Object list = DBTools.exQuery(sql, Shop.class, shopphone);
		return list;
	}
}
